package java06;

import java.util.Scanner;
public class Main05 {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			String choose = sc.next();
			if (choose.equals("new"))
			try{
				Student stu = new Student();
				String name = sc.next();
				stu.setName(name);
				int addScore = sc.nextInt();
				stu.addScore(addScore);
				System.out.println(stu);
			}catch(IllegalNameException e){
				System.out.println(e);
				break;
			}catch(IllegalScoreException e){
				System.out.println(e);
			}
			else 
				break;
		}
		sc.close();
		System.out.println("scanner closed");
	}

}
class IllegalNameException extends Exception{
	public IllegalNameException(String msg)  
    {  
        super(msg);  
    }  
}
class IllegalScoreException extends Exception{
	public IllegalScoreException(String msg)  
    {  
        super(msg);  
    }  
}

class Student{
	private String name;
	private int score;
	public String getName() {
		return name;
	}
	public void setName(String name) throws IllegalNameException {
		if(name.toCharArray()[0]>'0' && name.toCharArray()[0] < '9')
			throw new IllegalNameException("the first char of name must not be digit, name="+name);
		else 
			this.name = name;
	}
	public int getScore() {
		return score;
	}
	public void setScore(int score) {
		this.score = score;
	}
	
	public int addScore(int score) throws IllegalScoreException{
		if(this.score+score<0||this.score+score>100)
			throw new IllegalScoreException("score out of range, score=" + (this.score + score));
		else this.score=this.score+score;
		return this.score; 
		
	}
	@Override
	public String toString() {
		return "Student [name=" + name + ", score=" + score + "]";
	}
	
	
}

